package com.lzx.iteam.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lzx.iteam.ApprovalCreateActivity;
import com.lzx.iteam.R;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * **********************************
 * User: zhangshuai
 * Date: 2016年 04月 07日
 * Time: 下午5:18
 *
 * @QQ : 1234567890
 * **********************************
 */
public class ApprovalGridAdapter extends BaseAdapter {

    private List<String> mList;
    private Context mContext;

    public ApprovalGridAdapter(List<String> mList, Context mContext) {
        this.mList = mList;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.approval_gv_item,null);
            holder.img = (ImageView) convertView.findViewById(R.id.approval_item_iv);
            holder.name = (TextView) convertView.findViewById(R.id.approval_item_tv);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        holder.name.setText(mList.get(position));
        switch (position){
            case 0:
                holder.img.setBackgroundResource(R.drawable.ap_travel_selector);
                break;
            case 1:
                holder.img.setBackgroundResource(R.drawable.ap_leave_selector);
                break;
            case 2:
                holder.img.setBackgroundResource(R.drawable.ap_out_selector);
                break;
            /*case 3:
                holder.img.setBackgroundResource(R.drawable.ap_sign_selector);
                break;*/
            default:
                break;
        }

        return convertView;
    }
    private class ViewHolder {
        ImageView img;
        TextView name;
    }

}
